﻿using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using System.Text.Json;
using FastReport.DevComponents.DotNetBar.Controls;
using ExCSS;
using Traceability.Commont.Domains.BatchManagementFiles;
using Traceability.Commont.Domains.ScratchTheFat;

namespace Butcher.winform.EnterpriseForms.productiones
{
    public partial class productionAdd : Form
    {
        public productionAdd()
        {
            InitializeComponent();
            getType();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            string url = @"http://localhost:5229/api/Ending/ProductionScratchesCreate";
            HttpClient client = new HttpClient();
            ProductionScratches ct = new ProductionScratches();
            RadioButton rb = new RadioButton();
            if (rb.Checked && radioButton1.Text == "按重量分配")
            {
                ct.Distribution = 0;
            }
            else
            {
                ct.Distribution = 1;
            }
            ct.ProductionSummary = textBox1.Text;
            ct.DocumentNumber = textBox2.Text;
            ct.BulkSlaughterNo = comboBox1.Text;
            ct.Team = textBox4.Text;
            ct.DocumentsTime = Convert.ToDateTime(dateTimePicker1.Text);
            ct.Team = textBox4.Text;
            ct.FatOil = Convert.ToDecimal(textBox5.Text);
            textBox2.Text = DateTime.Now.ToString("yyyy-MM-dd");
            var sh = 0;
            var content = new StringContent(JsonSerializer.Serialize<ProductionScratches>(ct));
            content.Headers.Remove("Content-Type");
            content.Headers.Add("Content-Type", "application/json");
            string result = client.PostAsync(url, content).Result.Content.ReadAsStringAsync().Result;
            JObject info = JObject.Parse(result);
            var saaa = result;
            saaa = info["messges"].Value<string>();
            if (saaa != null)
            {
                sh = 1;
                MessageBox.Show("新增成功");
                //SearchClient departmentview = new SearchClient();
                //this.Hide();
                //departmentview.ShowDialog();
            }
            else
            {
                sh = 0;
                MessageBox.Show("新增失败");
            }
        }
        public void getType()
        {
            BulkSlaughter res = new BulkSlaughter();
            string url = @"http://localhost:5229/api/Batch/BulkSlaughterSearch";
            HttpClient client = new HttpClient();
            var content = new StringContent(JsonSerializer.Serialize<BulkSlaughter>(res));
            content.Headers.Remove("Content-Type");
            content.Headers.Add("Content-Type", "application/json");
            string result = client.PostAsync(url, content).Result.Content.ReadAsStringAsync().Result;
            JObject info = JObject.Parse(result);
            var aaa = info["date"].Value<JArray>();
            List<BulkSlaughter> enterprises = aaa.ToObject<List<BulkSlaughter>>();
            this.comboBox1.DataSource = enterprises;
            this.comboBox1.DisplayMember = "BulkSlaughterNo";
            this.comboBox1.ValueMember = "BulkSlaughterId";
        }

        private void textBox4_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
        }
    }
}
